package com.project.frba.bifront.client.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.google.gwt.user.client.rpc.IsSerializable;

public class Dashboard implements IsSerializable {

	public static Integer DUAL = 2;
	public static Integer QUAD = 4;
	public static Integer WIDTH = 600;
	public static Integer DUAL_HEIGHT = 490;
	public static Integer QUAD_HEIGHT = 265;
	
	private Long id;
	private String name;
	private Integer type;
	private Map<Integer, String> positions = new HashMap<Integer, String>();
	
	
	public Dashboard(){
		
	}
	
	public Dashboard(Integer type){
		this.setType(type);
	}

	public String getName() {
		return this.name;
	}

	public Integer getType() {
		return type;
	}

	public void setType(Integer type) {
		this.type = type;
		load();
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getFirst() {
		return positions.get(1);
	}

	public void setFirst(String first) {
		positions.put(1, first);
	}

	public String getFourth() {
		return positions.get(4);
	}

	public void setFourth(String fourth) {
		if(!type.equals(this.DUAL)){
			positions.put(4, fourth);			
		}
	}

	public String getSecond() {
		return positions.get(2);
	}

	public void setSecond(String second) {
		positions.put(2, second);
	}

	public String getThird() {
		return positions.get(3);
	}

	public void setThird(String third) {
		if(!type.equals(this.DUAL)){			
			positions.put(3, third);
		}
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	
	public static String getField(Integer position){
		switch (position) {
		case 1:
			return "first";
		case 2:
			return "second";
		case 3:
			return "third";
		case 4:
			return "fourth";
		}
		return "";
	}

	public String getKey() {
		return getId().toString() + "-" + getType();
	}
	
	public List<Integer> getFreePositions(){
		List<Integer> freePositions = new ArrayList<Integer>();
		for (Integer position : positions.keySet()) {
			if(positions.get(position) == null){
				freePositions.add(position);
			}
		}
		
		return freePositions;
	}
	
	public String getChartInfoFromPosition(Integer position){
		return positions.get(position);
	}
	
	private void load(){
		for (int i = 1; i <= this.getType() ; i++) {
			positions.put(i, null);
		}
	}
}
